﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Extension;

[AddComponentMenu("UI/SubjectiveButton")]
public class SubjectiveButton : Button
{
    [SerializeField]
    List<CommandSubject> m_subjects = new List<CommandSubject>();
    public List<CommandSubject> subjects { get { return m_subjects; } }

    protected override void OnEnable()
    {
        base.OnEnable();
        onClick.AddListener(InvokeSubjects);
    }

    void InvokeSubjects()
    {
        subjects.ForEach(s => s.Invoke() );
    }

    protected override void OnDisable()
    {
        base.OnDisable();
        onClick.RemoveAllListeners();
    }

#if WRB_HIGHSTAKES
    SoundManager m_soundManger = null;
    SoundManager SoundManger
    { get {
            if (m_soundManger.isNull())
            {
                GameObject sm = GameObject.Find("SoundManager");
                if (sm.isNotNull()) m_soundManger = sm.GetComponent<SoundManager>();
            }
            return m_soundManger; }  }

    protected override void Awake()
    {
        base.Awake();
        onClick.AddListener(() => {
            if (SoundManger.isNotNull())
                SoundManger.PlaySound(SoundEffect.Button_Tap);
        });
    }
#endif
}
